import { NButton } from "naive-ui";
import { getSlotsDom } from "../utils";
import type { ButtonProps } from "naive-ui";
import type { BaseComponentType } from "../types";
import type { HTMLAttributes } from "vue";
export type ButtonFactoryConstructorType = {
  props?: ButtonProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
  iconSlot?: BaseComponentType;
};
export class ButtonFactory {
  private defaultSlot: BaseComponentType = null;
  private iconSlot: BaseComponentType = null;
  private props: ButtonProps = {};
  private attrs: HTMLAttributes = {};
  constructor(param?: ButtonFactoryConstructorType) {
    if (param?.props) this.setProps(param.props);
    if (param?.defaultSlot) this.setDefault(param.defaultSlot);
    if (param?.iconSlot) this.setIcon(param.iconSlot);
    if (param?.attrs) this.setAttrs(param.attrs);
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: ButtonProps) {
    this.props = props;
    return this;
  }
  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }
  setIcon(component: BaseComponentType) {
    this.iconSlot = component;
    return this;
  }

  create() {
    return (
      <NButton {...this.attrs} {...this.props}>
        {{
          default: () => getSlotsDom(this.defaultSlot),
          icon: () => getSlotsDom(this.iconSlot),
        }}
      </NButton>
    );
  }
}
